function deepClone(obj){
    // 类型判断
    var checkType = function(obj){
        let val = Object.prototype.toString.call(obj).toLocaleLowerCase();
        return val.substring(8,val.length-1);
    }

    // 函数拷贝
    function fnClone(fn, o){
        return fn.bind(o);
    }

    // 数组拷贝
    function arrayClone(arr){
        let temp = [];
        arr.forEach(v=>{
            let type = checkType(v);
            if( type === 'array'){
                temp.push(arrayClone(v));
            }else if(type === 'object'){
                temp.push(objClone(v));
            }else{
                temp.push(v);
            }
        });
        return temp;
    }

    // 对象拷贝
    function objClone(data){
        let temp = {};
        for(let k in data){
            let type = checkType(data[k]);
            if(type === 'function'){
                temp[k] = fnClone(data[k], temp);
            }else if( type === 'array'){
                temp[k] = arrayClone(data[k]);
            }else if(type === 'object'){
                temp[k] = objClone(data[k]);
            }else{
                temp[k] = data[k];
            }
        }
        return temp;
    }

    // 获取参数类型
    var type = checkType(obj);
    
    switch (type) {
        case 'array': 
            return arrayClone(obj);
        case 'object':
            return objClone(obj);
        default:
            return obj;
    }
}

export default deepClone;